@title = "注册"
@signup_slogan = [
  "每一个ID,都是一段美好的姻缘"
  "XXXX"
]

div class: "page-header", ->
  h1 ->
    text @title
    small -> @signup_slogan.choice()

form id:"register", method:'POST', class:'well form-horizontal', ->
  if @form?.errors?.invite
    div class:"alert", ->
      a class:"close", "data-dismiss": "alert", href:"#", "x"
      h4 class:"alert-heading", "警告"
      text @form.errors.invite
  div class:"row-fluid", ->
    fieldset ->
      div class:"control-group", ->
        label class:"control-label", for:"invite", "邀请码:"
        div class:"controls", ->
          input name:'invite',type:'text', value: "#{ @form?.invite || ''}"
          span class:'help-inline', "#{ @form?.errors?.invite || ''}"

      div class:"control-group", ->
        label class:"control-label", for:"email", "邮箱:"
        div class:"controls", ->
          input name:'email',type:'text', value: "#{ @form?.email || ''}"
          span class:'help-inline', "#{ @form?.errors?.email || ''}"

      div class:"control-group", ->
        label class:"control-label", for:"nickname", "昵称:"
        div class:"controls", ->
          input name:'nickname',type:'text', value: "#{ @form?.nickname || ''}"
          span class:'help-inline', "#{ @form?.errors?.nickname || ''}"

      div class:"control-group", ->
        label class:"control-label", for:"password", "密码:"
        div class:"controls", ->
          input id:"password", name:'password',type:'password'
          span class:'help-inline', "#{ @form?.errors?.password || ''}"

      div class:"control-group", ->
        label class:"control-label", for:"repassword", "确认密码:"
        div class:"controls", ->
          input name:"repassword",type:"password"

    div class:"form-actions", ->
      button class:"btn btn-primary",type:"submit", -> span -> span "注册"
      a id:"cancel", href:"/", "先逛逛"

coffeescript ->
  $("#register")
    .submit((e)->
      t = $(e.target)
      if !t.valid()
        return false
    ).validate
      rules:
        invite:
          required: true
        email:
          required: true, email: true
        nickname:
          required: true, minlength: 2
        password:
          required: true, minlength: 4
        repassword:
          required: true, equalTo: "#password"
      messages:
        email:
          required: "必须填写用户名"
          email: "请输入正确的Email地址"
        nickname:
          required: "昵称是必须的哟", minlength: "长度需要长一点"
        password:
          required: "必须填写密码", minlength: "密码最小4位"
        repassword:
          required: "确认密码必填", equalTo: "你难道就忘记了吗?"
        invite:
          required: "邀请码必填"
  $("#cancel").click (e)->
    window.location = window.location.origin
    return false
